package vn.ikame.android.plugin;

import java.io.IOException;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;

public class BaseActivity extends Activity {
	public static final String APP_PACKAGE = "vn.ikame.android.truyenf17";
	public static final String DATA_LINK = "http://data.ikame.vn/";
	public static final int APP_ID = 3;
	
	public static INotification noti;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if(noti == null){
			noti = new INotification(this, "", "", "", "", 0, 0);
			getNotification(this);
		} else {
			noti.setContext(this);
		}
	}
	
	public void getNotification(final Context ctx) {
		try {
			new AsyncTask<Void, Void, String>() {
				@Override
				protected void onPreExecute() {
					
				}

				@Override
				protected String doInBackground(Void... arg0) {
					try {
						Parser.getNotification(noti, DATA_LINK + "services/appServer.php?index=notification&appid=" + APP_ID);

					} catch (IOException e) { 
						// TODO Auto-generated catch block
						e.printStackTrace();
						System.out.println("Không kết nối được đến server 2");
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
						System.out.println("Không kết nối được đến server 3");
					}
					return "";
				}

				// Hoàn thành truy vấn
				@Override 
				protected void onPostExecute(String result) {
					if(noti != null){
//						noti.setContext(ctx);
						noti.showNotice();
					}
					
					Log.d("HienPL", "Đăn" + noti.getName()); 
					try {
						
					} catch (Exception e) {
					}
				}
			}.execute();
		} catch (Exception e) {
		}
	}
}
